package com.shadow.cloud.security.controller;

import com.shadow.cloud.common.bo.R;
import com.shadow.cloud.security.entity.VersionEntity;
import com.shadow.cloud.security.service.VersionService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@AllArgsConstructor
@RestController
@RequestMapping("version")
public class VersionController {

    private final VersionService versionService;

    @GetMapping("list")
    public R list(final String query) {
        List<VersionEntity> list = versionService.pageVersion(query);
        return R.success(R.SUCCESS_MSG, list);
    }

    @GetMapping("detail")
    public R detail(@RequestParam final String id) {
        VersionEntity entity = versionService.getById(id);
        return R.success(R.SUCCESS_MSG, entity);
    }

    @PostMapping("save")
    public R save(@RequestBody final VersionEntity version) {
        versionService.save(version);
        return R.success();
    }

    @PostMapping("changeActivated")
    public R changeActivated(@RequestParam("id") final String id) {
        versionService.changeActivated(id);
        return R.success();
    }

    @PostMapping("delete")
    public R delete(@RequestParam("id") final String id) {
        versionService.removeById(id);
        return R.success();
    }
}
